#include "pfs_base.h"
#include <vector>

int Score(const Solution& solution, const PFS_Item& pfs_item) {
  using std::vector;
	vector<int> endtimes(pfs_item.machine_num() + 1);
	endtimes.front() = 0; 

	const int first_job = solution.front();
	for (size_t i = 1 ; i < endtimes.size() ; ++i) {
		endtimes[i] = endtimes[i-1] + pfs_item[i-1][first_job];
	}

	for (size_t i = 1 ; i < solution.size() ; ++i) {  // loop jobs
		for (size_t j = 1 ; j < endtimes.size() ; ++j) {  // loop machines
			endtimes[j] = (endtimes[j-1] > endtimes[j])? endtimes[j-1] :endtimes[j]; // better performance than std::max
			endtimes[j] += pfs_item[j-1][solution[i]];
		}
	}

	return endtimes.back();
}
